// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyavtScalarMetaData.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>

// ****************************************************************************
// Module: PyavtScalarMetaData
//
// Purpose:
//   Contains scalar metadata attributes
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a avtScalarMetaData.
//
struct avtScalarMetaDataObject
{
    PyObject_HEAD
    avtScalarMetaData *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewavtScalarMetaData(int);
std::string
PyavtScalarMetaData_ToString(const avtScalarMetaData *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    str = PyavtVarMetaData_ToString(atts, prefix, forLogging);

    if(atts->treatAsASCII)
        snprintf(tmpStr, 1000, "%streatAsASCII = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%streatAsASCII = 0\n", prefix);
    str += tmpStr;
    const char *enumerationType_names = "NONE, ByValue, ByRange, ByBitMask, ByNChooseR";
    switch (atts->GetEnumerationType())
    {
      case avtScalarMetaData::None:
          snprintf(tmpStr, 1000, "%senumerationType = %sNONE  # %s\n", prefix, prefix, enumerationType_names);
          str += tmpStr;
          break;
      case avtScalarMetaData::ByValue:
          snprintf(tmpStr, 1000, "%senumerationType = %sByValue  # %s\n", prefix, prefix, enumerationType_names);
          str += tmpStr;
          break;
      case avtScalarMetaData::ByRange:
          snprintf(tmpStr, 1000, "%senumerationType = %sByRange  # %s\n", prefix, prefix, enumerationType_names);
          str += tmpStr;
          break;
      case avtScalarMetaData::ByBitMask:
          snprintf(tmpStr, 1000, "%senumerationType = %sByBitMask  # %s\n", prefix, prefix, enumerationType_names);
          str += tmpStr;
          break;
      case avtScalarMetaData::ByNChooseR:
          snprintf(tmpStr, 1000, "%senumerationType = %sByNChooseR  # %s\n", prefix, prefix, enumerationType_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    {   const stringVector &enumNames = atts->enumNames;
        snprintf(tmpStr, 1000, "%senumNames = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < enumNames.size(); ++i)
        {
            snprintf(tmpStr, 1000, "\"%s\"", enumNames[i].c_str());
            str += tmpStr;
            if(i < enumNames.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const doubleVector &enumRanges = atts->enumRanges;
        snprintf(tmpStr, 1000, "%senumRanges = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < enumRanges.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%g", enumRanges[i]);
            str += tmpStr;
            if(i < enumRanges.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const double *enumAlwaysExclude = atts->enumAlwaysExclude;
        snprintf(tmpStr, 1000, "%senumAlwaysExclude = (", prefix);
        str += tmpStr;
        for(int i = 0; i < 2; ++i)
        {
            snprintf(tmpStr, 1000, "%g", enumAlwaysExclude[i]);
            str += tmpStr;
            if(i < 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const double *enumAlwaysInclude = atts->enumAlwaysInclude;
        snprintf(tmpStr, 1000, "%senumAlwaysInclude = (", prefix);
        str += tmpStr;
        for(int i = 0; i < 2; ++i)
        {
            snprintf(tmpStr, 1000, "%g", enumAlwaysInclude[i]);
            str += tmpStr;
            if(i < 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    const char *enumPartialCellMode_names = "Include, Exclude, Dissect";
    switch (atts->GetEnumPartialCellMode())
    {
      case avtScalarMetaData::Include:
          snprintf(tmpStr, 1000, "%senumPartialCellMode = %sInclude  # %s\n", prefix, prefix, enumPartialCellMode_names);
          str += tmpStr;
          break;
      case avtScalarMetaData::Exclude:
          snprintf(tmpStr, 1000, "%senumPartialCellMode = %sExclude  # %s\n", prefix, prefix, enumPartialCellMode_names);
          str += tmpStr;
          break;
      case avtScalarMetaData::Dissect:
          snprintf(tmpStr, 1000, "%senumPartialCellMode = %sDissect  # %s\n", prefix, prefix, enumPartialCellMode_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    {   const intVector &enumGraphEdges = atts->enumGraphEdges;
        snprintf(tmpStr, 1000, "%senumGraphEdges = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < enumGraphEdges.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", enumGraphEdges[i]);
            str += tmpStr;
            if(i < enumGraphEdges.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const stringVector &enumGraphEdgeNames = atts->enumGraphEdgeNames;
        snprintf(tmpStr, 1000, "%senumGraphEdgeNames = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < enumGraphEdgeNames.size(); ++i)
        {
            snprintf(tmpStr, 1000, "\"%s\"", enumGraphEdgeNames[i].c_str());
            str += tmpStr;
            if(i < enumGraphEdgeNames.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const intVector &enumGraphEdgeNameIndexs = atts->enumGraphEdgeNameIndexs;
        snprintf(tmpStr, 1000, "%senumGraphEdgeNameIndexs = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < enumGraphEdgeNameIndexs.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", enumGraphEdgeNameIndexs[i]);
            str += tmpStr;
            if(i < enumGraphEdgeNameIndexs.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    snprintf(tmpStr, 1000, "%senumNChooseRN = %d\n", prefix, atts->GetEnumNChooseRN());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%senumNChooseRMaxR = %d\n", prefix, atts->GetEnumNChooseRMaxR());
    str += tmpStr;
    const char *missingDataType_names = "MissingData_None, MissingData_Value, MissingData_Valid_Min, MissingData_Valid_Max, MissingData_Valid_Range";
    switch (atts->GetMissingDataType())
    {
      case avtScalarMetaData::MissingData_None:
          snprintf(tmpStr, 1000, "%smissingDataType = %sMissingData_None  # %s\n", prefix, prefix, missingDataType_names);
          str += tmpStr;
          break;
      case avtScalarMetaData::MissingData_Value:
          snprintf(tmpStr, 1000, "%smissingDataType = %sMissingData_Value  # %s\n", prefix, prefix, missingDataType_names);
          str += tmpStr;
          break;
      case avtScalarMetaData::MissingData_Valid_Min:
          snprintf(tmpStr, 1000, "%smissingDataType = %sMissingData_Valid_Min  # %s\n", prefix, prefix, missingDataType_names);
          str += tmpStr;
          break;
      case avtScalarMetaData::MissingData_Valid_Max:
          snprintf(tmpStr, 1000, "%smissingDataType = %sMissingData_Valid_Max  # %s\n", prefix, prefix, missingDataType_names);
          str += tmpStr;
          break;
      case avtScalarMetaData::MissingData_Valid_Range:
          snprintf(tmpStr, 1000, "%smissingDataType = %sMissingData_Valid_Range  # %s\n", prefix, prefix, missingDataType_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    {   const double *missingData = atts->GetMissingData();
        snprintf(tmpStr, 1000, "%smissingData = (", prefix);
        str += tmpStr;
        for(int i = 0; i < 2; ++i)
        {
            snprintf(tmpStr, 1000, "%g", missingData[i]);
            str += tmpStr;
            if(i < 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    return str;
}

static PyObject *
avtScalarMetaData_Notify(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtScalarMetaData_SetTreatAsASCII(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the treatAsASCII in the object.
    obj->data->treatAsASCII = cval;

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtScalarMetaData_GetTreatAsASCII(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->treatAsASCII?1L:0L);
    return retval;
}

/*static*/ PyObject *
avtScalarMetaData_SetEnumerationType(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 5)
    {
        std::stringstream ss;
        ss << "An invalid enumerationType value was given." << std::endl;
        ss << "Valid values are in the range [0,4]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " None";
        ss << ", ByValue";
        ss << ", ByRange";
        ss << ", ByBitMask";
        ss << ", ByNChooseR";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the enumerationType in the object.
    obj->data->SetEnumerationType(avtScalarMetaData::EnumTypes(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtScalarMetaData_GetEnumerationType(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetEnumerationType()));
    return retval;
}

/*static*/ PyObject *
avtScalarMetaData_SetEnumNames(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;

    stringVector vec;

    if (PyUnicode_Check(args))
    {
        char const *val = PyUnicode_AsUTF8(args);
        std::string cval = std::string(val);
        if (val == 0 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ string");
        }
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyUnicode_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a unicode string", (int) i);
            }

            char const *val = PyUnicode_AsUTF8(item);
            std::string cval = std::string(val);

            if (val == 0 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ string", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more string(s)");

    obj->data->enumNames = vec;
    // Mark the enumNames in the object as modified.
    obj->data->SelectAll();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtScalarMetaData_GetEnumNames(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;
    // Allocate a tuple the with enough entries to hold the enumNames.
    const stringVector &enumNames = obj->data->enumNames;
    PyObject *retval = PyTuple_New(enumNames.size());
    for(size_t i = 0; i < enumNames.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyString_FromString(enumNames[i].c_str()));
    return retval;
}

/*static*/ PyObject *
avtScalarMetaData_SetEnumRanges(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;

    doubleVector vec;

    if (PyNumber_Check(args))
    {
        double val = PyFloat_AsDouble(args);
        double cval = double(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ double");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ double");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            double val = PyFloat_AsDouble(item);
            double cval = double(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more doubles");

    obj->data->enumRanges = vec;
    // Mark the enumRanges in the object as modified.
    obj->data->SelectAll();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtScalarMetaData_GetEnumRanges(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;
    // Allocate a tuple the with enough entries to hold the enumRanges.
    const doubleVector &enumRanges = obj->data->enumRanges;
    PyObject *retval = PyTuple_New(enumRanges.size());
    for(size_t i = 0; i < enumRanges.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(enumRanges[i]));
    return retval;
}

/*static*/ PyObject *
avtScalarMetaData_SetEnumAlwaysExclude(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;

    PyObject *packaged_args = 0;
    double *vals = obj->data->enumAlwaysExclude;

    if (!PySequence_Check(args) || PyUnicode_Check(args))
        return PyErr_Format(PyExc_TypeError, "Expecting a sequence of numeric args");

    // break open args seq. if we think it matches this API's needs
    if (PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PySequence_Check(packaged_args) && !PyUnicode_Check(packaged_args) &&
            PySequence_Size(packaged_args) == 2)
            args = packaged_args;
    }

    if (PySequence_Size(args) != 2)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "Expecting 2 numeric args");
    }

    for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
    {
        PyObject *item = PySequence_GetItem(args, i);

        if (!PyNumber_Check(item))
        {
            Py_DECREF(item);
            Py_XDECREF(packaged_args);
            return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
        }

        double val = PyFloat_AsDouble(item);
        double cval = double(val);

        if (val == -1 && PyErr_Occurred())
        {
            Py_XDECREF(packaged_args);
            Py_DECREF(item);
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
        {
            Py_XDECREF(packaged_args);
            Py_DECREF(item);
            return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
        }
        Py_DECREF(item);

        vals[i] = cval;
    }

    Py_XDECREF(packaged_args);

    // Mark the enumAlwaysExclude in the object as modified.
    obj->data->SelectAll();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtScalarMetaData_GetEnumAlwaysExclude(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;
    // Allocate a tuple the with enough entries to hold the enumAlwaysExclude.
    PyObject *retval = PyTuple_New(2);
    const double *enumAlwaysExclude = obj->data->enumAlwaysExclude;
    for(int i = 0; i < 2; ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(enumAlwaysExclude[i]));
    return retval;
}

/*static*/ PyObject *
avtScalarMetaData_SetEnumAlwaysInclude(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;

    PyObject *packaged_args = 0;
    double *vals = obj->data->enumAlwaysInclude;

    if (!PySequence_Check(args) || PyUnicode_Check(args))
        return PyErr_Format(PyExc_TypeError, "Expecting a sequence of numeric args");

    // break open args seq. if we think it matches this API's needs
    if (PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PySequence_Check(packaged_args) && !PyUnicode_Check(packaged_args) &&
            PySequence_Size(packaged_args) == 2)
            args = packaged_args;
    }

    if (PySequence_Size(args) != 2)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "Expecting 2 numeric args");
    }

    for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
    {
        PyObject *item = PySequence_GetItem(args, i);

        if (!PyNumber_Check(item))
        {
            Py_DECREF(item);
            Py_XDECREF(packaged_args);
            return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
        }

        double val = PyFloat_AsDouble(item);
        double cval = double(val);

        if (val == -1 && PyErr_Occurred())
        {
            Py_XDECREF(packaged_args);
            Py_DECREF(item);
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
        {
            Py_XDECREF(packaged_args);
            Py_DECREF(item);
            return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
        }
        Py_DECREF(item);

        vals[i] = cval;
    }

    Py_XDECREF(packaged_args);

    // Mark the enumAlwaysInclude in the object as modified.
    obj->data->SelectAll();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtScalarMetaData_GetEnumAlwaysInclude(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;
    // Allocate a tuple the with enough entries to hold the enumAlwaysInclude.
    PyObject *retval = PyTuple_New(2);
    const double *enumAlwaysInclude = obj->data->enumAlwaysInclude;
    for(int i = 0; i < 2; ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(enumAlwaysInclude[i]));
    return retval;
}

/*static*/ PyObject *
avtScalarMetaData_SetEnumPartialCellMode(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 3)
    {
        std::stringstream ss;
        ss << "An invalid enumPartialCellMode value was given." << std::endl;
        ss << "Valid values are in the range [0,2]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " Include";
        ss << ", Exclude";
        ss << ", Dissect";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the enumPartialCellMode in the object.
    obj->data->SetEnumPartialCellMode(avtScalarMetaData::PartialCellModes(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtScalarMetaData_GetEnumPartialCellMode(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetEnumPartialCellMode()));
    return retval;
}

/*static*/ PyObject *
avtScalarMetaData_SetEnumGraphEdges(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->enumGraphEdges = vec;
    // Mark the enumGraphEdges in the object as modified.
    obj->data->SelectAll();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtScalarMetaData_GetEnumGraphEdges(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;
    // Allocate a tuple the with enough entries to hold the enumGraphEdges.
    const intVector &enumGraphEdges = obj->data->enumGraphEdges;
    PyObject *retval = PyTuple_New(enumGraphEdges.size());
    for(size_t i = 0; i < enumGraphEdges.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(enumGraphEdges[i])));
    return retval;
}

/*static*/ PyObject *
avtScalarMetaData_SetEnumGraphEdgeNames(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;

    stringVector vec;

    if (PyUnicode_Check(args))
    {
        char const *val = PyUnicode_AsUTF8(args);
        std::string cval = std::string(val);
        if (val == 0 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ string");
        }
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyUnicode_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a unicode string", (int) i);
            }

            char const *val = PyUnicode_AsUTF8(item);
            std::string cval = std::string(val);

            if (val == 0 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ string", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more string(s)");

    obj->data->enumGraphEdgeNames = vec;
    // Mark the enumGraphEdgeNames in the object as modified.
    obj->data->SelectAll();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtScalarMetaData_GetEnumGraphEdgeNames(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;
    // Allocate a tuple the with enough entries to hold the enumGraphEdgeNames.
    const stringVector &enumGraphEdgeNames = obj->data->enumGraphEdgeNames;
    PyObject *retval = PyTuple_New(enumGraphEdgeNames.size());
    for(size_t i = 0; i < enumGraphEdgeNames.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyString_FromString(enumGraphEdgeNames[i].c_str()));
    return retval;
}

/*static*/ PyObject *
avtScalarMetaData_SetEnumGraphEdgeNameIndexs(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->enumGraphEdgeNameIndexs = vec;
    // Mark the enumGraphEdgeNameIndexs in the object as modified.
    obj->data->SelectAll();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtScalarMetaData_GetEnumGraphEdgeNameIndexs(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;
    // Allocate a tuple the with enough entries to hold the enumGraphEdgeNameIndexs.
    const intVector &enumGraphEdgeNameIndexs = obj->data->enumGraphEdgeNameIndexs;
    PyObject *retval = PyTuple_New(enumGraphEdgeNameIndexs.size());
    for(size_t i = 0; i < enumGraphEdgeNameIndexs.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(enumGraphEdgeNameIndexs[i])));
    return retval;
}

/*static*/ PyObject *
avtScalarMetaData_SetEnumNChooseRN(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the enumNChooseRN in the object.
    obj->data->SetEnumNChooseRN(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtScalarMetaData_GetEnumNChooseRN(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetEnumNChooseRN()));
    return retval;
}

/*static*/ PyObject *
avtScalarMetaData_SetEnumNChooseRMaxR(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the enumNChooseRMaxR in the object.
    obj->data->SetEnumNChooseRMaxR(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtScalarMetaData_GetEnumNChooseRMaxR(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetEnumNChooseRMaxR()));
    return retval;
}

/*static*/ PyObject *
avtScalarMetaData_SetMissingDataType(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 5)
    {
        std::stringstream ss;
        ss << "An invalid missingDataType value was given." << std::endl;
        ss << "Valid values are in the range [0,4]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " MissingData_None";
        ss << ", MissingData_Value";
        ss << ", MissingData_Valid_Min";
        ss << ", MissingData_Valid_Max";
        ss << ", MissingData_Valid_Range";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the missingDataType in the object.
    obj->data->SetMissingDataType(avtScalarMetaData::MissingData(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtScalarMetaData_GetMissingDataType(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetMissingDataType()));
    return retval;
}

/*static*/ PyObject *
avtScalarMetaData_SetMissingData(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;

    PyObject *packaged_args = 0;
    double *vals = obj->data->GetMissingData();

    if (!PySequence_Check(args) || PyUnicode_Check(args))
        return PyErr_Format(PyExc_TypeError, "Expecting a sequence of numeric args");

    // break open args seq. if we think it matches this API's needs
    if (PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PySequence_Check(packaged_args) && !PyUnicode_Check(packaged_args) &&
            PySequence_Size(packaged_args) == 2)
            args = packaged_args;
    }

    if (PySequence_Size(args) != 2)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "Expecting 2 numeric args");
    }

    for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
    {
        PyObject *item = PySequence_GetItem(args, i);

        if (!PyNumber_Check(item))
        {
            Py_DECREF(item);
            Py_XDECREF(packaged_args);
            return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
        }

        double val = PyFloat_AsDouble(item);
        double cval = double(val);

        if (val == -1 && PyErr_Occurred())
        {
            Py_XDECREF(packaged_args);
            Py_DECREF(item);
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
        {
            Py_XDECREF(packaged_args);
            Py_DECREF(item);
            return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
        }
        Py_DECREF(item);

        vals[i] = cval;
    }

    Py_XDECREF(packaged_args);

    // Mark the missingData in the object as modified.
    obj->data->SelectMissingData();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtScalarMetaData_GetMissingData(PyObject *self, PyObject *args)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)self;
    // Allocate a tuple the with enough entries to hold the missingData.
    PyObject *retval = PyTuple_New(2);
    const double *missingData = obj->data->GetMissingData();
    for(int i = 0; i < 2; ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(missingData[i]));
    return retval;
}



PyMethodDef PyavtScalarMetaData_methods[AVTSCALARMETADATA_NMETH] = {
    {"Notify", avtScalarMetaData_Notify, METH_VARARGS},
    {"SetTreatAsASCII", avtScalarMetaData_SetTreatAsASCII, METH_VARARGS},
    {"GetTreatAsASCII", avtScalarMetaData_GetTreatAsASCII, METH_VARARGS},
    {"SetEnumerationType", avtScalarMetaData_SetEnumerationType, METH_VARARGS},
    {"GetEnumerationType", avtScalarMetaData_GetEnumerationType, METH_VARARGS},
    {"SetEnumNames", avtScalarMetaData_SetEnumNames, METH_VARARGS},
    {"GetEnumNames", avtScalarMetaData_GetEnumNames, METH_VARARGS},
    {"SetEnumRanges", avtScalarMetaData_SetEnumRanges, METH_VARARGS},
    {"GetEnumRanges", avtScalarMetaData_GetEnumRanges, METH_VARARGS},
    {"SetEnumAlwaysExclude", avtScalarMetaData_SetEnumAlwaysExclude, METH_VARARGS},
    {"GetEnumAlwaysExclude", avtScalarMetaData_GetEnumAlwaysExclude, METH_VARARGS},
    {"SetEnumAlwaysInclude", avtScalarMetaData_SetEnumAlwaysInclude, METH_VARARGS},
    {"GetEnumAlwaysInclude", avtScalarMetaData_GetEnumAlwaysInclude, METH_VARARGS},
    {"SetEnumPartialCellMode", avtScalarMetaData_SetEnumPartialCellMode, METH_VARARGS},
    {"GetEnumPartialCellMode", avtScalarMetaData_GetEnumPartialCellMode, METH_VARARGS},
    {"SetEnumGraphEdges", avtScalarMetaData_SetEnumGraphEdges, METH_VARARGS},
    {"GetEnumGraphEdges", avtScalarMetaData_GetEnumGraphEdges, METH_VARARGS},
    {"SetEnumGraphEdgeNames", avtScalarMetaData_SetEnumGraphEdgeNames, METH_VARARGS},
    {"GetEnumGraphEdgeNames", avtScalarMetaData_GetEnumGraphEdgeNames, METH_VARARGS},
    {"SetEnumGraphEdgeNameIndexs", avtScalarMetaData_SetEnumGraphEdgeNameIndexs, METH_VARARGS},
    {"GetEnumGraphEdgeNameIndexs", avtScalarMetaData_GetEnumGraphEdgeNameIndexs, METH_VARARGS},
    {"SetEnumNChooseRN", avtScalarMetaData_SetEnumNChooseRN, METH_VARARGS},
    {"GetEnumNChooseRN", avtScalarMetaData_GetEnumNChooseRN, METH_VARARGS},
    {"SetEnumNChooseRMaxR", avtScalarMetaData_SetEnumNChooseRMaxR, METH_VARARGS},
    {"GetEnumNChooseRMaxR", avtScalarMetaData_GetEnumNChooseRMaxR, METH_VARARGS},
    {"SetMissingDataType", avtScalarMetaData_SetMissingDataType, METH_VARARGS},
    {"GetMissingDataType", avtScalarMetaData_GetMissingDataType, METH_VARARGS},
    {"SetMissingData", avtScalarMetaData_SetMissingData, METH_VARARGS},
    {"GetMissingData", avtScalarMetaData_GetMissingData, METH_VARARGS},
    {NULL, NULL}
};

static void PyavtScalarMetaData_ExtendSetGetMethodTable()
{
    static bool extended = false;
    if (extended) return;
    extended = true;

    int i = 0;
    while (PyavtScalarMetaData_methods[i].ml_name)
        i++;
    int n = i;
    while (PyavtVarMetaData_methods[i-n+1].ml_name)
    {
        PyavtScalarMetaData_methods[i] = PyavtVarMetaData_methods[i-n+1];
        i++;
    }

    PyMethodDef nullMethod = {NULL, NULL};
    PyavtScalarMetaData_methods[i] = nullMethod;
}

//
// Type functions
//

static void
avtScalarMetaData_dealloc(PyObject *v)
{
   avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *avtScalarMetaData_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyavtScalarMetaData_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "treatAsASCII") == 0)
        return avtScalarMetaData_GetTreatAsASCII(self, NULL);
    if(strcmp(name, "enumerationType") == 0)
        return avtScalarMetaData_GetEnumerationType(self, NULL);
    if(strcmp(name, "None") == 0)
        return PyInt_FromLong(long(avtScalarMetaData::None));
    if(strcmp(name, "NONE") == 0)
        return PyInt_FromLong(long(avtScalarMetaData::None));
    if(strcmp(name, "ByValue") == 0)
        return PyInt_FromLong(long(avtScalarMetaData::ByValue));
    if(strcmp(name, "ByRange") == 0)
        return PyInt_FromLong(long(avtScalarMetaData::ByRange));
    if(strcmp(name, "ByBitMask") == 0)
        return PyInt_FromLong(long(avtScalarMetaData::ByBitMask));
    if(strcmp(name, "ByNChooseR") == 0)
        return PyInt_FromLong(long(avtScalarMetaData::ByNChooseR));

    if(strcmp(name, "enumNames") == 0)
        return avtScalarMetaData_GetEnumNames(self, NULL);
    if(strcmp(name, "enumRanges") == 0)
        return avtScalarMetaData_GetEnumRanges(self, NULL);
    if(strcmp(name, "enumAlwaysExclude") == 0)
        return avtScalarMetaData_GetEnumAlwaysExclude(self, NULL);
    if(strcmp(name, "enumAlwaysInclude") == 0)
        return avtScalarMetaData_GetEnumAlwaysInclude(self, NULL);
    if(strcmp(name, "enumPartialCellMode") == 0)
        return avtScalarMetaData_GetEnumPartialCellMode(self, NULL);
    if(strcmp(name, "Include") == 0)
        return PyInt_FromLong(long(avtScalarMetaData::Include));
    if(strcmp(name, "Exclude") == 0)
        return PyInt_FromLong(long(avtScalarMetaData::Exclude));
    if(strcmp(name, "Dissect") == 0)
        return PyInt_FromLong(long(avtScalarMetaData::Dissect));

    if(strcmp(name, "enumGraphEdges") == 0)
        return avtScalarMetaData_GetEnumGraphEdges(self, NULL);
    if(strcmp(name, "enumGraphEdgeNames") == 0)
        return avtScalarMetaData_GetEnumGraphEdgeNames(self, NULL);
    if(strcmp(name, "enumGraphEdgeNameIndexs") == 0)
        return avtScalarMetaData_GetEnumGraphEdgeNameIndexs(self, NULL);
    if(strcmp(name, "enumNChooseRN") == 0)
        return avtScalarMetaData_GetEnumNChooseRN(self, NULL);
    if(strcmp(name, "enumNChooseRMaxR") == 0)
        return avtScalarMetaData_GetEnumNChooseRMaxR(self, NULL);
    if(strcmp(name, "missingDataType") == 0)
        return avtScalarMetaData_GetMissingDataType(self, NULL);
    if(strcmp(name, "MissingData_None") == 0)
        return PyInt_FromLong(long(avtScalarMetaData::MissingData_None));
    if(strcmp(name, "MissingData_Value") == 0)
        return PyInt_FromLong(long(avtScalarMetaData::MissingData_Value));
    if(strcmp(name, "MissingData_Valid_Min") == 0)
        return PyInt_FromLong(long(avtScalarMetaData::MissingData_Valid_Min));
    if(strcmp(name, "MissingData_Valid_Max") == 0)
        return PyInt_FromLong(long(avtScalarMetaData::MissingData_Valid_Max));
    if(strcmp(name, "MissingData_Valid_Range") == 0)
        return PyInt_FromLong(long(avtScalarMetaData::MissingData_Valid_Range));

    if(strcmp(name, "missingData") == 0)
        return avtScalarMetaData_GetMissingData(self, NULL);

    if(strcmp(name, "__methods__") != 0)
    {
        PyObject *retval = PyavtVarMetaData_getattr(self, name);
        if (retval) return retval;
    }

    PyavtScalarMetaData_ExtendSetGetMethodTable();

    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyavtScalarMetaData_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyavtScalarMetaData_methods[i].ml_name),
                PyString_FromString(PyavtScalarMetaData_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyavtScalarMetaData_methods, self, name);
}

int
PyavtScalarMetaData_setattr(PyObject *self, char *name, PyObject *args)
{
    if (PyavtVarMetaData_setattr(self, name, args) != -1)
        return 0;
    else
        PyErr_Clear();

    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "treatAsASCII") == 0)
        obj = avtScalarMetaData_SetTreatAsASCII(self, args);
    else if(strcmp(name, "enumerationType") == 0)
        obj = avtScalarMetaData_SetEnumerationType(self, args);
    else if(strcmp(name, "enumNames") == 0)
        obj = avtScalarMetaData_SetEnumNames(self, args);
    else if(strcmp(name, "enumRanges") == 0)
        obj = avtScalarMetaData_SetEnumRanges(self, args);
    else if(strcmp(name, "enumAlwaysExclude") == 0)
        obj = avtScalarMetaData_SetEnumAlwaysExclude(self, args);
    else if(strcmp(name, "enumAlwaysInclude") == 0)
        obj = avtScalarMetaData_SetEnumAlwaysInclude(self, args);
    else if(strcmp(name, "enumPartialCellMode") == 0)
        obj = avtScalarMetaData_SetEnumPartialCellMode(self, args);
    else if(strcmp(name, "enumGraphEdges") == 0)
        obj = avtScalarMetaData_SetEnumGraphEdges(self, args);
    else if(strcmp(name, "enumGraphEdgeNames") == 0)
        obj = avtScalarMetaData_SetEnumGraphEdgeNames(self, args);
    else if(strcmp(name, "enumGraphEdgeNameIndexs") == 0)
        obj = avtScalarMetaData_SetEnumGraphEdgeNameIndexs(self, args);
    else if(strcmp(name, "enumNChooseRN") == 0)
        obj = avtScalarMetaData_SetEnumNChooseRN(self, args);
    else if(strcmp(name, "enumNChooseRMaxR") == 0)
        obj = avtScalarMetaData_SetEnumNChooseRMaxR(self, args);
    else if(strcmp(name, "missingDataType") == 0)
        obj = avtScalarMetaData_SetMissingDataType(self, args);
    else if(strcmp(name, "missingData") == 0)
        obj = avtScalarMetaData_SetMissingData(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
avtScalarMetaData_print(PyObject *v, FILE *fp, int flags)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)v;
    fprintf(fp, "%s", PyavtScalarMetaData_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
avtScalarMetaData_str(PyObject *v)
{
    avtScalarMetaDataObject *obj = (avtScalarMetaDataObject *)v;
    return PyString_FromString(PyavtScalarMetaData_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *avtScalarMetaData_Purpose = "Contains scalar metadata attributes";
#else
static char *avtScalarMetaData_Purpose = "Contains scalar metadata attributes";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(avtScalarMetaDataType,         \
                  "avtScalarMetaData",           \
                  avtScalarMetaDataObject,       \
                  avtScalarMetaData_dealloc,     \
                  avtScalarMetaData_print,       \
                  PyavtScalarMetaData_getattr,   \
                  PyavtScalarMetaData_setattr,   \
                  avtScalarMetaData_str,         \
                  avtScalarMetaData_Purpose,     \
                  avtScalarMetaData_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
avtScalarMetaData_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &avtScalarMetaDataType
         || Py_TYPE(other) != &avtScalarMetaDataType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    avtScalarMetaData *a = ((avtScalarMetaDataObject *)self)->data;
    avtScalarMetaData *b = ((avtScalarMetaDataObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static avtScalarMetaData *defaultAtts = 0;
static avtScalarMetaData *currentAtts = 0;

static PyObject *
NewavtScalarMetaData(int useCurrent)
{
    avtScalarMetaDataObject *newObject;
    newObject = PyObject_NEW(avtScalarMetaDataObject, &avtScalarMetaDataType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new avtScalarMetaData(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new avtScalarMetaData(*defaultAtts);
    else
        newObject->data = new avtScalarMetaData;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapavtScalarMetaData(const avtScalarMetaData *attr)
{
    avtScalarMetaDataObject *newObject;
    newObject = PyObject_NEW(avtScalarMetaDataObject, &avtScalarMetaDataType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (avtScalarMetaData *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
avtScalarMetaData_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewavtScalarMetaData(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef avtScalarMetaDataMethods[] = {
    {"avtScalarMetaData", avtScalarMetaData_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *avtScalarMetaDataObserver = 0;

std::string
PyavtScalarMetaData_GetLogString()
{
    std::string s("avtScalarMetaData = avtScalarMetaData()\n");
    if(currentAtts != 0)
        s += PyavtScalarMetaData_ToString(currentAtts, "avtScalarMetaData.", true);
    return s;
}

static void
PyavtScalarMetaData_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("avtScalarMetaData = avtScalarMetaData()\n");
        s += PyavtScalarMetaData_ToString(currentAtts, "avtScalarMetaData.", true);
        cb(s);
    }
}

void
PyavtScalarMetaData_StartUp(avtScalarMetaData *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyavtScalarMetaData_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(avtScalarMetaDataObserver == 0)
    {
        avtScalarMetaDataObserver = new ObserverToCallback(subj,
            PyavtScalarMetaData_CallLogRoutine, (void *)data);
    }

}

void
PyavtScalarMetaData_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete avtScalarMetaDataObserver;
    avtScalarMetaDataObserver = 0;
}

PyMethodDef *
PyavtScalarMetaData_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return avtScalarMetaDataMethods;
}

bool
PyavtScalarMetaData_Check(PyObject *obj)
{
    return (obj->ob_type == &avtScalarMetaDataType);
}

avtScalarMetaData *
PyavtScalarMetaData_FromPyObject(PyObject *obj)
{
    avtScalarMetaDataObject *obj2 = (avtScalarMetaDataObject *)obj;
    return obj2->data;
}

PyObject *
PyavtScalarMetaData_New()
{
    return NewavtScalarMetaData(0);
}

PyObject *
PyavtScalarMetaData_Wrap(const avtScalarMetaData *attr)
{
    return WrapavtScalarMetaData(attr);
}

void
PyavtScalarMetaData_SetParent(PyObject *obj, PyObject *parent)
{
    avtScalarMetaDataObject *obj2 = (avtScalarMetaDataObject *)obj;
    obj2->parent = parent;
}

void
PyavtScalarMetaData_SetDefaults(const avtScalarMetaData *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new avtScalarMetaData(*atts);
}

